package com.demo.jwt.controller;


import com.demo.jwt.entity.User;
import com.demo.jwt.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Value("${myInfo.name}")
    private String name2;

    @Value("${myInfo.password}")
    private String password2;

    @GetMapping("/login")
    public String login(String name, String password) {
        if(name.equals(name2) && password.equals(password2)){
            User user = new User();
            user.setName(name);
            user.setPassword(password);
            return JwtUtils.getToken(user);    //  账号密码正确，生成token
        }else{
            return "账号或密码不正确，登录失败!";
        }
    }

    @GetMapping("/test")
    public String test(){
        return "测试无权限页面";
    }
}
